import Cookies from 'js-cookie'

const TokenKey = 'access_token'
const _csrfToken = 'csrfToken'

export function getToken() {
  return Cookies.get(TokenKey) || localStorage.getItem(TokenKey)
}

export function setToken(token: string) {
  localStorage.setItem(TokenKey, token)
  return Cookies.set(TokenKey, token, {
    expires: 3,
    path: '/',
  })
}

export function removeToken() {
  localStorage.setItem(TokenKey, '')
  return Cookies.remove(TokenKey)
}

export function csrfToken() {
  return Cookies.get(_csrfToken) || localStorage.getItem(_csrfToken)
}
